<!--考试申请-->
<template>
    <div>
            <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right" v-loading="loading">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>考试申请</el-breadcrumb-item>
        </el-breadcrumb>
         <div style="margin: 10px auto;"></div>
          <el-alert
                title="练习过得学时请记得评论，不然会影响你的实际学时！"
                type="success">
         </el-alert>
        <div class="main1" v-if="user.testStatus != '0' ">
            您当前正在进行科目训练：<span style="color: red;">{{user.testStatus}}</span>
        </div>

        <div v-if="user.testState == '0' ">
        <div style="margin:20px auto" v-if="user.testStatus == '2' || user.testStatus == '3'">
            <span style="font-size:22px">学时完成百分比:</span>
            <el-progress :text-inside="true" :stroke-width="24" :percentage="percentage" status="success"></el-progress>
            <div style="margin:20px auto">
            <el-popconfirm
                title="确定申请吗？"
                @confirm="appleText"
                >
            <el-button :disabled="percentage != 100 "  slot="reference" type="primary">一键申请考试</el-button>
            </el-popconfirm>
            </div>
        </div>
        <div v-else-if="user.testStatus == '0' ">
                恭喜完成考试！
        </div>
        <div v-else>
            <el-popconfirm
                title="确定申请吗？"
                @confirm="appleText"
                >
            <el-button  slot="reference" type="primary">一键申请考试</el-button>
            </el-popconfirm>
        </div>
        </div>
        <div v-else>
                您有考试在申请
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            user:'',
            percentage:0,
            loading:false
        }
    },
    created(){
        this.user = JSON.parse(window.sessionStorage.getItem("user"));
        this.findSurplusHour();
    },
    methods: {
        appleText(){ //申请考试
                this.myLoading();
               
                this.$api.get("/user/token/appleText","",res=>{ 
                        if(res.data.code == 200){
                             this.$notify.success({
                                message: '申请成功，等待审核！页面即将刷新！',
                                duration: 0
                            });
                            //同步用户信息
                            this.$api.get("/user/token/findUserByid",'',Response=>{
              
                                        if(Response.data.code == 200){
                                            this.user = Response.data.data;
                                            window.sessionStorage.setItem("user",JSON.stringify(Response.data.data));
                                            setTimeout(()=>{
                                                window.location.reload();
                                            },1000)
                                        }
                            })
                        }
                })
        },
        findSurplusHour(){    //查询学时完成度
            this.myLoading()
            this.$api.get("/order/token/findSurplusHour","",res=>{
                    if(res.data.code == 200){
                        this.percentage = res.data.data;
                    }
            })
        },
        myLoading(){
            this.loading =true;
            setTimeout(()=>{
                this.loading =false;
            },500)
        }
    },  
}
</script>
<style scoped>
.main1{
    margin: 10px auto;
    text-align: center;
    font-size: 24px;
    color: gray;
}
</style>